from fastapi_utils.api_model import APIModel
from pydantic import BaseModel, Field, ConfigDict
from datetime import datetime
from typing import Optional, List


class DeptSchema(BaseModel):
    model_config = ConfigDict(from_attributes=True)

    id: int = Field(description="部门ID")
    parent_id: int = Field(description="父级编号")
    dept_name: str = Field(description="部门名称")
    sort: int = Field(description="排序")
    leader: str = Field(description="负责人")
    phone: str = Field(description="联系方式")
    email: str = Field(description="邮箱")
    status: int = Field(description="状态(1开启,0关闭)")
    remark: Optional[str] = Field(default=None, description="备注")
    address: Optional[str] = Field(default=None, description="详细地址")
    create_at: datetime = Field(description="创建时间")
    update_at: datetime = Field(description="更新时间")


class DeptTree(DeptSchema):
    children: List["DeptTree"] = []


class DeptOut(BaseModel):
    """部门树"""

    status: dict = {}
    data: List[DeptSchema] = []


class DeptSaveSchema(APIModel):
    parent_id: int = Field(0, description="父级编号")
    dept_name: str = Field(..., description="部门名称")
    sort: int = Field(0, description="排序")
    leader: str = Field(..., description="负责人")
    phone: str = Field(..., description="联系方式")
    email: str = Field(..., description="邮箱")
    status: int = Field(1, description="状态(1开启,0关闭)")
    remark: Optional[str] = Field(None, description="备注")
    address: Optional[str] = Field(None, description="详细地址")

    model_config = ConfigDict(from_attributes=True)


class DeptUpdateSchema(DeptSaveSchema):
    deptId: int = Field(..., description="部门ID")


class DeptEnableDisableSchema(BaseModel):
    deptId: int = Field(..., description="部门ID")

    model_config = ConfigDict(from_attributes=True)
